package com.huaru.formboot.form.controller;


import com.huaru.formboot.form.entity.Dto.ComponentTemplate;
import com.huaru.formboot.form.service.ComponentTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 组件模板表 前端控制器
 * </p>
 *
 * @author wz
 * @since 2021-04-15
 */
@Api(tags = "组件列表相关接口")
@RestController
@RequestMapping("/form/component-template")
public class ComponentTemplateController {
    /**
     *组件服务
     */
    @Autowired
    private ComponentTemplateService componentTemplateService;

    /**
     * 新增组件
     * @param
     * @return
     */
    @ApiOperation("新增组件接口")
    @PostMapping("/insert")
    public Integer insert(@RequestBody ComponentTemplate componentTemplate){
    return componentTemplateService.insertComponentTemplate(componentTemplate);
    }

    /**
     * 获取所有组件模板
     * @return
     */
    @ApiOperation("获取所有组件模板接口")
    @PostMapping("/getComponentTemplate")
    public List<ComponentTemplate> getComponentTemplate(){

        return componentTemplateService.getAllComponentTemplate();
    }
    /**
     * 根据条件获取组件模板
     * @return
     */
    @ApiOperation("根据条件获取组件模板接口")
    @PostMapping("/getComTemplateByName")
    public List<ComponentTemplate> getComTemplateByName(@RequestBody ComponentTemplate componentTemplate){
        return componentTemplateService.getComponentTemplateByName(componentTemplate.getComponentName());
    }
    /**
     * 根据id删除
     * @return
     */
    @ApiOperation("根据id删除组件模板接口")
    @PostMapping("/delete")
    public Integer delete(@RequestBody ComponentTemplate componentTemplate){
    return componentTemplateService.deleteByComponentId(componentTemplate.getComponentId());
    }
    /**
     * 根据id更新组件
     */
    @ApiOperation("根据id更新组件模板接口")
    @PostMapping("/update")
    public Integer update(@RequestBody ComponentTemplate componentTemplate){
    return componentTemplateService.updateComponentTemplateById(componentTemplate);
    }
    /**
     *根据组件id更新元素样式
     */
    @ApiOperation("根据组件id更新元素接口")
    @PostMapping("/updateElementStyle")
    public Integer updateElementStyle(@RequestBody ComponentTemplate componentTemplate){
     return componentTemplateService.updateElementStyle(componentTemplate);
    }
}

